<!DOCTYPE html>
<html lang="zh-CN">
 <head> 
  <#include "../head.html" />
 </head> 
 <body>
   <#include "../layout/top.html" />
   <div class="container bs-docs-container"> 
  <div class="row"> 
   <#include "../layout/left-menu.html" />
   <div class="col-md-9" role="main"> 
    <!-- NAVI --> 
    <ul class="nav nav-tabs" id="PageTab"> 
     <li class="active"><a href="#" data-toggle="tab" onclick="manage();" aria-expanded="true">管理账号</a></li> 
     <li id="manual_tab" class=""><a href="#" data-toggle="tab" onclick="manual();" aria-expanded="false">手动绑定</a></li>
     <li class=""><a href="#" data-toggle="tab" onclick="auto();" aria-expanded="false">自动绑定</a></li> 
    </ul> 
    <br /> 
    <!-- END NAVI --> 
    <!-- PAGE1: ADMINID--> 
    <div id="manage" class="tab-pane fade active in"> 
     <div class="alert alert-info" role="alert">
       	当前已绑定<span id="manage_alert_id">0</span>个账号，普通用户最多可以绑定5个用户 
     </div> 
	    <table class="table table-striped">
	     <thead> 
	      <tr> 
	       <th>序号</th> 
	       <th style="width:25%">百度名称</th> 
	       <th style="width:55%">BDUSS Cookie</th> 
	       <th>操作</th> 
	      </tr> 
	     </thead> 
	     <tbody id="manage_tbody_id">
	     </tbody> 
	    </table> 
    </div> 
	<!-- PAGE1：END -->
	<!-- PAGE2: ADMINID--> 
    <div id="manual" class="tab-pane fade active in"> 
      <form id="manual_form" action="${base}/user/manual" method="post">
     	 <div class="input-group">
		  <span class="input-group-addon">输入BDUSS</span>
		  <input type="text" class="form-control" name="bduss" value="" />
		  <span class="input-group-btn"><input type="submit" class="btn btn-primary" value="点击提交"></span>
		</div>
      </form>
      <br>
      <br>
      <b>手动获取BDUSS教程：</b>
      <br>
      <br>
      <div class="panel panel-default">
		<div class="panel-heading" onclick="$('#win_bduss').fadeToggle();"><h3 class="panel-title"><span class="glyphicon glyphicon-chevron-down"></span> 通过工具获取</h3></div>
		<div class="panel-body" id="win_bduss" style="display: block;">
		    1.<a href="${base}/res/bootstrap/doc/get_bduss.exe">点击此处下载 贴吧BDUSS获取器</a>
		    <br><br>2.请确保已安装了 <b>.Net Framework 3.0</b> [ 正版Win7已自带 ]
		    <br><br>3.请运行此程序，按照要求输入账号信息，然后将获取到的 BDUSS 填入上面的表单即可
		</div>
	  </div>
	  <br>
	  <div class="panel panel-default">
	<div class="panel-heading" onclick="$('#chrome_bduss').fadeToggle();"><h3 class="panel-title"><span class="glyphicon glyphicon-chevron-down"></span> 点击查看在 Chrome 浏览器下的绑定方法</h3></div>
	<div class="panel-body" id="chrome_bduss" style="display: none;">
	    1.使用 Chrome 或 Chromium 内核的浏览器
		<br><br>2.打开百度首页 <a href="http://www.baidu.com" target="_blank">http://www.baidu.com/</a>
    <br><br>3.右键，点击 <b>查看网页信息</b>
		<br><br>4.确保已经登录百度，然后点击 <b>显示 Cookie 和网站数据</b>
		<br><br>5.如图，依次展开 <b>passport.baidu.com</b> -&gt; <b>Cookie</b> -&gt; <b>BDUSS</b>
		<br><br><a href="${base}/res/bootstrap/doc/baiduid.png" target="_blank"><img src="${base}/res/bootstrap/doc/baiduid.png"></a>
		<br><br>6.按下 Ctrl+A 全选，然后复制并输入到上面的表单即可
    <br><br>请注意，一旦退出登录，可能导致 BDUSS 失效，因此建议在隐身模式下登录
	</div>
</div>
    </div> 
	<!-- PAGE2：END -->
	<!-- PAGE3: ADMINID--> 
    <div id="auto" class="tab-pane fade active in" style="display: none;"> 
     <div class="alert alert-warning" role="alert">
       	由于百度强制开启了异地登陆验证，很可能导致自动绑定失败。如果你确定输入无误但却提示账号密码错误，请使用<a href="javascript:manual1();">手动绑定</a>
     </div> 
      <form action="${base}/user/auto" method="post">
      	<div class="input-group">
      		<span class="input-group-addon">百度账号</span>
   			<input type="text" class="form-control" name="bdAccount" placeholder="请输入百度账户名，建议填写邮箱" required />
      	</div>
      	<br>
      	<div class="input-group">
      		<span class="input-group-addon">密码</span>
   			<input type="password" name="password" class="form-control" placeholder="请输入百度密码" required />
      	</div>
      	<br>
      	<input type="submit" class="btn btn-primary" value="点击绑定">
      </form>
    </div> 
	<!-- PAGE3：END -->
   </div> 
  </div>  
  </div>
 <script type="text/javascript">
 $(function(){
	 manage();
	 <#if mod?? && mod=='first'>
	 	layer.msg("您还没有绑定贴吧账号，请先绑定",{icon: 2});
	 </#if>
 });
 function manage(){
	 $('#manual').css('display','none');
	 $('#auto').css('display','none');
	 $('#manage').css('display','');
	 $.ajax({
		type : 'POST', 
      	dataType :"json",
      	contentType: "application/json; charset=utf-8",
        data : {},
		url : "${base}/user/baiDuManage",
		success : function(data){
			$("#manage_tbody_id").html("");
			$("#manage_alert_id").html(data.length);
			if(data.length > 0){
				var htmStr = "";
				$.each(data, function(index,ob){
					htmStr += "<tr>";
					htmStr += "<td>" + (index+1) + "</td>";
					htmStr += "<td>" + ob.nickName + "</td>";
					htmStr += "<td><input type='text' class='form-control' readonly='' value='"+ ob.bduss +"' /></td>";
					htmStr += "<td><a class='btn btn-warning' href='javascript:void(0);' onclick='unbundling(\""+ ob.guid +"\");'>解绑</a></td>";
				});
				$("#manage_tbody_id").html(htmStr);
			}
		}
	});
 }
 function manual(){
	 //手动绑定
	 $('#manage').css('display','none');
	 $('#auto').css('display','none');
	 $('#manual').css('display','');
 }
 function manual1(){//手动绑定
	 $('#manage').css('display','none');
	 $('#auto').css('display','none');
	 $('#manual').css('display','');
	 $('#manual_tab').click();
 }
 function auto(){
	 //自动绑定
	 $('#manage').css('display','none');
	 $('#manual').css('display','none');
	 $('#auto').css('display','');
 }
 function unbundling(guid){
	 //解绑用户
	 $.ajax({
			type : 'POST', 
			url : "${base}/user/unbundling?guid="+guid,
			success : function(data){
				if(data.status == 0){
					location.href = "${base}/user/baiduid";
				}
			}
		});
 }
 </script>
 </body>
</html>